<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>公告编辑</title>
  <link rel="stylesheet" th:th:href="@{@{/layui/css/layui.css}}">
</head>
<body class="layui-layout-body" >
<div class="layui-layout layui-layout-admin">

<div class="layui-body">
	
	<blockquote class="layui-elem-quote" th:text="${msg}" th:style="'color: green;display:' + (${msg} == null ? 'none' : 'block')"></blockquote>
	
	<form class="layui-form" th:action="@{/index_page/notice/save}" method="post">
		<input type="hidden" name="id" th:value="${notice == null} ? '' : ${notice.id}">
		<div class="layui-form-item">
      		<label class="layui-form-label"><span style="color: red;">*</span>公告内容</label>
      		<div class="layui-input-inline">
      			<input id="content" name="content" class="layui-input" type="text" placeholder="请输入" autocomplete="off" 
      				lay-verify="required|content" maxlength="16"
      				th:value="${notice == null} ? '' : ${notice.content}">
      			<div class="layui-input-inline layui-form-mid layui-word-aux">
			    	请输入8～16个字
			    </div>
     		</div>
  		</div>
  		<div class="layui-form-item">
		    <label class="layui-form-label"><span style="color: red;">*</span>排序权重</label>
		    <div class="layui-input-inline">
		      	<input name="sort" class="layui-input" type="text" placeholder="请输入数字" autocomplete="off" maxlength="4"
		      		lay-verify="required|noticeSort" th:value="${notice} == null ? '1' : ${notice.sort}">
		    </div>
		    <div class="layui-input-inline layui-form-mid layui-word-aux">
		    	请输入1～9999的整数
		    </div>
	  	</div>
		<div class="layui-form-item">
    		<div class="layui-input-block">
      			<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
      			<a th:href="@{/index_page/notice/list}"  class="layui-btn">取消</a>
    		</div>
  		</div>
	</form>
	
	<div style="height: 70px"></div>
</div>
  
</div>
<script th:src="@{/layui/jquery.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script>
$(document).ready(function(){ 
	$(".layui-body").css({"left": "10px","top": "10px"});
}); 
//一般直接写在一个js文件中
var form;
layui.use(['layer', 'form'], function(){
	var layer = layui.layer;
	form = layui.form;

	form.verify({
		content: function(value, item) {
			if(value.length < 8 || value.length > 16)
				return '限制8～16字';
		}
		, noticeSort: function(value, item) {
			var patrn = /^[1-9][0-9]{0,3}$/;
		  	if (!patrn.test(value)) {
		  		return '请输入1～9999的整数';
		  	}
		}
	});
});
</script>
</body>
</html>